package com.learn.mapper;

import com.learn.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

//    /*
//    * 查询个数
//     */
//    @Select("select count(*) from emp")
//    Long count();
//
//    /*
//    * 分页查询
//     */
//    @Select("select * from emp limit #{begin},#{size}")
//    List<Emp> selectByPage(Integer begin, Integer size);

    /*
    * 查询所有
     */
    @Select("select * from emp")
    List<Emp> list();

    /*
    * 根据条件查询 结合PageHelper分页
     */
    List<Emp> selectByCondition(String name, Short gender, LocalDate begin, LocalDate end);

    /*
    * 根据id删除
     */
    void deleteByIds(List<Integer> ids);


    @Insert("insert into emp (username, name, gender,image, job, entrydate,dept_id,create_time,update_time) values " +
            "(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void add(Emp emp);

    /*
    * 根据id查询
     */
    @Select("select * from emp where id = #{id}")
    Emp getDataById(Integer id);

    /*
    * 修改员工
     */
    void update(Emp emp);

    /*
    * 登录
     */

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPassword(Emp emp);


    @Delete("delete from emp where dept_id = #{deptId}")
    void DeleteByDeptId(Integer deptId);
}
